package com.itheima.pinda.authority.biz.service.auth.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.pinda.authority.biz.dao.auth.ResourceMapper;
import com.itheima.pinda.authority.biz.service.auth.ResourceService;
import com.itheima.pinda.authority.dto.auth.ResourceQueryDTO;
import com.itheima.pinda.authority.entity.auth.Resource;
import com.itheima.pinda.common.constant.CacheKey;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.oschina.j2cache.CacheChannel;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 资源业务逻辑实现
 * @Author: ysf
 * @CreateTime: 2024-11-13  15:30
 * @Version: 1.0
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper,Resource> implements ResourceService {


    /**
    * 查询用户可用的资源权限并进行缓存
    * @param resourceQueryDTO
    * @return List<Resource>
    */
    @Override
    public List<Resource> findVisibleResource(ResourceQueryDTO resourceQueryDTO) {

//        //查询所有资源权限
//        List<Resource> resourceList = this.baseMapper.findVisibleResource(resourceQueryDTO);
//        //筛选出请求方式+请求url地址
//        if(resourceList != null && resourceList.size() > 0){
//            List<String> resource = resourceList
//                    .stream()
//                    .map((r) -> {
//                        return r.getMethod() + r.getUrl();
//                    }).collect(Collectors.toList());
//
//            //存入缓存 用用户id做key 形式为：GET/user/pages
//            String key = resourceQueryDTO.getUserId().toString();
//            cacheChannel.set(CacheKey.USER_RESOURCE,key,resource);
//        }

        return this.baseMapper.findVisibleResource(resourceQueryDTO);
    }
}
